package it.traveldream.worker.beans;

import it.traveldreamClient.beans.UserMgr;
import it.traveldreamClient.beans.dto.UserDTO;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean(name="addemploybean")
@RequestScoped
public class AddEmployBean {
	
	@EJB
	private UserMgr usrMgr;
	
	private UserDTO impiegato;

	public UserDTO getImpiegato() {
		return impiegato;
	}

	public void setImpiegato(UserDTO impiegato) {
		this.impiegato = impiegato;
	}

	public AddEmployBean(){
		impiegato = new UserDTO();
	}

	public UserMgr getUsrMgr() {
		return usrMgr;
	}

	public void setUsrMgr(UserMgr usrMgr) {
		this.usrMgr = usrMgr;
	}
	
	public String register() {
		try {
			usrMgr.saveEmp(impiegato);
		} catch (Exception e) {
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,e.getMessage(), 
					"")); 
			return"register";
		}
		return "index?faces-redirect=true";
	}
}
